class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int left=0,right=nums.size()-1;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(target>nums[mid]) left=mid+1;
            else right=mid;
        }
        if(nums[left]<target) return left+1;
        else return left;

    }
};

//比较简单，自己实现
class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int sz=nums.size();
        int left=0,right=sz-1,mid=0;
        while(left<=right)
        {
            mid=left+(right-left)/2;
            if(nums[mid]==target)
                return mid;
            else if(nums[mid]>target)
                right=mid-1;
            else
                left=mid+1;
        }
        return nums[mid]<target?mid+1:mid;
    }
};
